<template>
  <div class="config">
    <div class="header">
      <div
        class="item"
        v-for="(item, index) in list"
        :key="index"
        :class="{ active: current === index + 1 }"
        @click="selectTab(index)"
      >
        <span class="icon">{{ index + 1 }}</span>
        <span class="text">{{ item.name }}</span>
      </div>
    </div>
    <div class="body">
      <select-chart v-show="current == 1"></select-chart>
      <config-data v-show="current == 2"></config-data>
    </div>
  </div>
</template>

<script>
import SelectChart from './modules/config/selectChart'
import ConfigData from './modules/config/configData'

export default {
  name: 'DashboardConfig',
  components: {
    SelectChart,
    ConfigData
  },
  data () {
    return {
      current: 1,
      list: [{ name: '选择图表' }, { name: '配置数据,图表' }, { name: '保存图表' }]
    }
  },
  created () {
    this.$bus.on('selectedChart', data => {
      console.log(data)
      this.current = 2
    })
  },
  beforeDestroy () {
    // 销毁监听事件，防止多次触发
    this.$bus.$off('selectedChart')
  },
  methods: {
    selectTab (index) {
      console.log(index)
      this.current = index + 1
    }
  }
}
</script>

<style lang="less" scoped>
.config {
  .header {
    display: flex;
    justify-content: center;
    margin: auto;
    border-bottom: 1px solid #ddd;
    padding-bottom: 14px;
    .item {
      width: 18%;
      position: relative;
      text-align: center;
      cursor: pointer;
      .icon {
        display: inline-block;
        width: 28px;
        height: 28px;
        margin-right: 8px;
        font-size: 14px;
        line-height: 28px;
        text-align: center;
        border: 1px solid rgba(0, 0, 0, 0.25);
        border-radius: 28px;
        transition: background-color 0.3s, border-color 0.3s;
      }
      .text {
        position: relative;
        display: inline-block;
        padding-right: 16px;
        color: rgba(0, 0, 0, 0.65);
        font-size: 16px;
        line-height: 28px;
      }
      &.active {
        .icon {
          background: #2d78ea;
          color: #fff;
          border: 1px solid #2d78ea;
        }
        .text {
          font-weight: bold;
          color: #2d78ea;
        }
      }
      &:after {
        position: absolute;
        top: 50%;
        left: 100%;
        display: inline-block;
        width: 12px;
        height: 12px;
        margin-top: -7px;
        margin-left: -20px;
        border: 1px solid rgba(0, 0, 0, 0.25);
        border-bottom: none;
        border-left: none;
        transform: rotate(45deg);
        content: '';
      }
      &:last-child {
        &::after {
          display: none;
        }
      }
    }
  }
  .body {
  }
}
</style>
